﻿'=====================================================================
'模 块 名：SystemData

'描    述：系统全局变量

'依赖模块：My.MyApplication
'          由MyApplication_Startup()调用

'版本历史：见《版本历史.txt》
'=====================================================================
Imports System.IO
Imports System.IO.Ports
Imports System.Text

Namespace FL_8x0.Common


    Module SystemData


        Public Const SUPER_USER_NAME = "boyi"     '超级用户名
        Public Const SUPER_PASSWORD = "4346"      '超级密码

        Public Const SN = "c5f1f38c64f0e2f28946900d717f0e11"

        Public log As BoyiLog    'log日志对象
        Public idWorker As IdWorker '分布式ID

        Public g_strStartupPath As String     'exe程序运行目录
        Public g_strExcelPath As String       'Excel模板目录
        Public g_strJsonPath As String        'JSON文件目录
        Public g_strBinPath As String         'Bin插件文件目录

        Public g_strDatabasePath As String       '本地Access数据库目录
        Public g_strDatabaseProvider As String   '数据库接口

        '显示字符串
        Public g_strErrorMsg() As String      '错误号信息

        Public g_strGPUnit() As String        '测试压单位

        Public g_strLeakUnit() As String      '泄漏量单位


        Public g_strTestType() As String      '检测类型
        Public g_strTestResult() As String    '检测结果
        Public g_strPress() As String         '检测环节
        Public g_strPoint() As String         '小数点显示格式
        Public g_strEPoint() As String        '科学计数法显示格式
        Public g_strResultTitle() As String   '检测结果标题
        Public g_strUserTitle() As String    '用户管理标题

        Public g_strStatesMain() As String     '控制主时序（nsMain状态机）
        Public g_strStatesLeak() As String     'MS检漏环节（nsLeak状态机）
        Public g_strStatesPara() As String     '检漏参数时序（nsPara状态机）
        Public g_strStatesTank() As String     'TANK调平衡时序（nsTank状态机）
        Public g_strFittingMode() As String    'Fitiing模式

        Public g_strBaudRate As List(Of String)


        '当前用户
        Public g_strUserName As String        '用户名
        Public g_strUserLevel As String       '用户权限等级


        Public g_serialPort As New SerialPort With {
            .PortName = "COM1",
            .Handshake = Handshake.None,
            .ReadBufferSize = 512,
            .BaudRate = 9600,
            .DataBits = 8,
            .StopBits = 1,
            .Parity = Parity.None}

        '=====================================================================
        '函 数 名: SystemStringInit
        '参    数: 
        '返 回 值: 
        '功能描述: 字符串初始化
        '=====================================================================
        Public Sub SystemStringInit()

            '当前用户
            g_strUserName = "空"
            g_strUserLevel = ""

            '错误号
            ReDim g_strErrorMsg(0 To 18)
            g_strErrorMsg(0) = "无错"
            g_strErrorMsg(1) = "ADC电路异常"
            g_strErrorMsg(2) = "IIC总线异常"
            g_strErrorMsg(3) = "EEPROM存储器异常"
            g_strErrorMsg(4) = "U盘电路异常"
            g_strErrorMsg(5) = "网络电路异常"
            g_strErrorMsg(6) = "RTC时钟异常"
            g_strErrorMsg(7) = "直压1超出允许范围"
            g_strErrorMsg(8) = "直压2超出允许范围"
            g_strErrorMsg(9) = "差压超出允许范围"
            g_strErrorMsg(10) = "温度超出允许范围"
            g_strErrorMsg(11) = "ADC超出允许范围"
            g_strErrorMsg(12) = "出厂数据设定超出允许范围"
            g_strErrorMsg(13) = "用户数据设定超出允许范围"
            g_strErrorMsg(14) = "差压零点校准错误（非零点）"
            g_strErrorMsg(15) = "直压1零点校准错误（非零点）"
            g_strErrorMsg(16) = "直压2零点校准错误（非零点）"
            g_strErrorMsg(17) = "加重平均修正值超限"
            g_strErrorMsg(18) = "排气不充分，残余压力过高"

            '测试压单位
            ReDim g_strGPUnit(0 To 17)
            g_strGPUnit(0) = "kPa"
            g_strGPUnit(1) = "kg/cm2"
            g_strGPUnit(2) = "PSI"
            g_strGPUnit(3) = "bar"
            g_strGPUnit(4) = "MPa"
            g_strGPUnit(5) = "hPa"
            g_strGPUnit(6) = "Pa"
            g_strGPUnit(7) = "mbar"
            g_strGPUnit(8) = "Torr"
            g_strGPUnit(9) = "ATM"
            g_strGPUnit(10) = "mH2O"
            g_strGPUnit(11) = "cmH2O"
            g_strGPUnit(12) = "mmH2O"
            g_strGPUnit(13) = "inchH2O"
            g_strGPUnit(14) = "mHg"
            g_strGPUnit(15) = "cmHg"
            g_strGPUnit(16) = "mmHg"
            g_strGPUnit(17) = "inchHg"

            '泄漏量单位
            ReDim g_strLeakUnit(0 To 16)
            g_strLeakUnit(0) = "Pa"
            g_strLeakUnit(1) = "用户压力单位"
            g_strLeakUnit(2) = "Pa/s"
            g_strLeakUnit(3) = "Pa/min"
            g_strLeakUnit(4) = "mL/s"
            g_strLeakUnit(5) = "mL/min"
            g_strLeakUnit(6) = "mL/h"
            g_strLeakUnit(7) = "Pa.cm3/s"
            g_strLeakUnit(8) = "Pa.m3/s"
            g_strLeakUnit(9) = "mbar.L/s"
            g_strLeakUnit(10) = "Torr.L/s"
            g_strLeakUnit(11) = "L/min"
            g_strLeakUnit(12) = "L/h"
            g_strLeakUnit(13) = "mm3/s"
            g_strLeakUnit(14) = "kPa/s"
            g_strLeakUnit(15) = "kPa/min"

            '检测类型
            ReDim g_strTestType(0 To 13)
            g_strTestType(0) = "准备"
            g_strTestType(1) = "启动"
            g_strTestType(2) = "停止"
            g_strTestType(3) = "CAL1"
            g_strTestType(4) = "CAL2"
            g_strTestType(5) = "CAL1+CAL2"
            g_strTestType(6) = "Fitting"
            g_strTestType(7) = "Fitting+CAL2"
            g_strTestType(8) = "气泡检测"
            g_strTestType(9) = "启动2(开漏孔)"
            g_strTestType(10) = "偏倚校准(小泄漏)"
            g_strTestType(11) = "偏倚校准(大泄漏)"
            g_strTestType(12) = "启动3(开TANK容积)"
            g_strTestType(13) = "单步"

            '控制主时序（nsMain状态机）
            ReDim g_strStatesMain(0 To 2)
            g_strStatesMain(0) = "装料"
            g_strStatesMain(1) = "检漏"
            g_strStatesMain(2) = "卸料"

            'MS检漏环节（nsLeak状态机）
            ReDim g_strStatesLeak(0 To 6)
            g_strStatesLeak(0) = "单机气密"
            g_strStatesLeak(1) = "缝隙容积检测"
            g_strStatesLeak(2) = "TANK调平衡"
            g_strStatesLeak(3) = "单机TANK气密"
            g_strStatesLeak(4) = "TANK容积检测"
            g_strStatesLeak(5) = "NG标准校准"
            g_strStatesLeak(6) = "泄漏检测"

            '检漏参数时序（nsPara状态机）
            ReDim g_strStatesPara(0 To 1)
            g_strStatesPara(0) = "参数和条件准备"
            g_strStatesPara(1) = "泄漏检测"

            'TANK调平衡时序（nsTank状态机）
            ReDim g_strStatesTank(0 To 1)
            g_strStatesTank(0) = "TANK粗调配容"
            g_strStatesTank(1) = "TANK精调平衡"

            '检测结果
            ReDim g_strTestResult(0 To 11)
            g_strTestResult(0) = "OK"
            g_strTestResult(1) = "LPNG"
            g_strTestResult(2) = "TPNG"
            g_strTestResult(3) = "+BNG"
            g_strTestResult(4) = "-BNG"
            g_strTestResult(5) = "+SNG"
            g_strTestResult(6) = "-SNG"
            g_strTestResult(7) = "+LNG"
            g_strTestResult(8) = "-LNG"
            g_strTestResult(9) = "+FNG"
            g_strTestResult(10) = "-FNG"
            g_strTestResult(11) = "ERR"

            '检测环节
            ReDim g_strPress(0 To 15)
            g_strPress(0) = "预热"
            g_strPress(1) = "准备"
            g_strPress(2) = "延时1"
            g_strPress(3) = "充气1"
            g_strPress(4) = "充气2"
            g_strPress(5) = "平衡1"
            g_strPress(6) = "平衡2"
            g_strPress(7) = "小漏检测"
            g_strPress(8) = "大漏检测"
            g_strPress(9) = "延时2"
            g_strPress(10) = "排气"
            g_strPress(11) = "延时3"
            g_strPress(12) = "打压"
            g_strPress(13) = "小漏基准"
            g_strPress(14) = "CAL1"
            g_strPress(15) = "CAL2"

            '小数点显示格式
            ReDim g_strPoint(0 To 5)
            g_strPoint(0) = "0"
            g_strPoint(1) = "0.0"
            g_strPoint(2) = "0.00"
            g_strPoint(3) = "0.000"
            g_strPoint(4) = "0.0000"
            g_strPoint(5) = "0.00000"

            '科学计数法显示格式
            ReDim g_strEPoint(0 To 5)
            g_strEPoint(0) = "0E+0"
            g_strEPoint(1) = "0.0E+0"
            g_strEPoint(2) = "0.00E+0"
            g_strEPoint(3) = "0.000E+0"
            g_strEPoint(4) = "0.0000E+0"
            g_strEPoint(5) = "0.00000E+0"

            '检测结果标题
            ReDim g_strResultTitle(0 To 72)
            g_strResultTitle(0) = "报告号"
            g_strResultTitle(1) = "产品号"
            g_strResultTitle(2) = "产品名称"
            g_strResultTitle(3) = "产品型号"
            g_strResultTitle(4) = "产品编码"
            g_strResultTitle(5) = "记录号"
            g_strResultTitle(6) = "日期时间"

            g_strResultTitle(7) = "小漏差压"
            g_strResultTitle(8) = "小漏结果"
            g_strResultTitle(9) = "小漏单位"
            g_strResultTitle(10) = "大漏差压"
            g_strResultTitle(11) = "大漏结果"
            g_strResultTitle(12) = "大漏单位"
            g_strResultTitle(13) = "启动时气源压力" 'kPa
            g_strResultTitle(14) = "平衡1被测物压力" 'kPa
            g_strResultTitle(15) = "测试压单位"
            g_strResultTitle(16) = "充气2结束差压(Pa)" 'Pa
            g_strResultTitle(17) = "平衡2结束差压(Pa)" 'Pa
            g_strResultTitle(18) = "小漏结束温度(℃)"
            g_strResultTitle(19) = "结果环节"
            g_strResultTitle(20) = "结果判定"
            g_strResultTitle(21) = "错误号"
            g_strResultTitle(22) = "检测类型"


            g_strResultTitle(23) = "使用组号"
            g_strResultTitle(24) = "时间_延时夹紧"
            g_strResultTitle(25) = "时间_充气1"
            g_strResultTitle(26) = "时间_充气2"
            g_strResultTitle(27) = "时间_平衡1"
            g_strResultTitle(28) = "时间_平衡2"
            g_strResultTitle(29) = "时间_小漏"
            g_strResultTitle(30) = "时间_大漏"
            g_strResultTitle(31) = "时间_延时排气"
            g_strResultTitle(32) = "时间_排气"
            g_strResultTitle(33) = "时间_延时松开"
            g_strResultTitle(34) = "时间_Fitting基准"
            g_strResultTitle(35) = "充气1上限"
            g_strResultTitle(36) = "充气1下限"
            g_strResultTitle(37) = "充气2上限"
            g_strResultTitle(38) = "充气2下限"
            g_strResultTitle(39) = "BNG上限" 'Pa
            g_strResultTitle(40) = "BNG下限" 'Pa
            g_strResultTitle(41) = "SNG上限" 'Pa
            g_strResultTitle(42) = "SNG下限" 'Pa
            g_strResultTitle(43) = "LNG上限" 'Pa
            g_strResultTitle(44) = "LNG下限" 'Pa
            g_strResultTitle(45) = "FNG上限" 'Pa
            g_strResultTitle(46) = "FNG下限" 'Pa

            g_strResultTitle(47) = "被测物容积(mL)"
            g_strResultTitle(48) = "基准物容积(mL)"
            g_strResultTitle(49) = "负向泄漏计算"
            g_strResultTitle(50) = "中途判定功能"
            g_strResultTitle(51) = "U盘保存"
            g_strResultTitle(52) = "小漏偏差校准模式"
            g_strResultTitle(53) = "小漏偏差值"
            g_strResultTitle(54) = "小漏线性校准模式"
            g_strResultTitle(55) = "小漏线性系数K"
            g_strResultTitle(56) = "小漏线性系数B"
            g_strResultTitle(57) = "大漏偏差校准模式"
            g_strResultTitle(58) = "大漏偏差值"
            g_strResultTitle(59) = "大漏线性校准模式"
            g_strResultTitle(60) = "大漏线性系数K"
            g_strResultTitle(61) = "大漏线性系数B"

            g_strResultTitle(62) = "加权平均补偿"
            g_strResultTitle(63) = "补偿值保存"
            g_strResultTitle(64) = "补偿值上限"
            g_strResultTitle(65) = "当前补偿值"
            g_strResultTitle(66) = "补偿系数"
            g_strResultTitle(67) = "补偿有效结果上限"

            g_strResultTitle(68) = "Fitting模式"
            g_strResultTitle(69) = "Fitting系数A"
            g_strResultTitle(70) = "Fitting系数B"
            g_strResultTitle(71) = "Fitting系数C"
            g_strResultTitle(72) = "标准漏孔值(mL/min)"


            ReDim g_strUserTitle(0 To 15)
            g_strUserTitle(0) = "用户名"
            g_strUserTitle(1) = "密码"
            g_strUserTitle(2) = "前3次密码"
            g_strUserTitle(3) = "是否启用"
            g_strUserTitle(4) = "泄漏检测权限"
            g_strUserTitle(5) = "添加产品权限"
            g_strUserTitle(6) = "编辑产品权限"
            g_strUserTitle(7) = "通用设置权限"
            g_strUserTitle(8) = "用户管理权限"
            g_strUserTitle(9) = "记录管理权限"
            g_strUserTitle(10) = "日志管理权限"
            g_strUserTitle(11) = "报表打印导出权限"
            g_strUserTitle(12) = "报表模板管理权限"
            g_strUserTitle(13) = "错误次数"
            g_strUserTitle(14) = "上次登录日期"
            g_strUserTitle(15) = "密码到期日"


            ReDim g_strFittingMode(0 To 4)
            g_strFittingMode(0) = "0"
            g_strFittingMode(1) = "1"
            g_strFittingMode(2) = "2"
            g_strFittingMode(3) = "3"
            g_strFittingMode(4) = "OFF"

            g_strBaudRate = New List(Of String) From {"1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"}


        End Sub


        '=====================================================================
        '函 数 名: CheckTextNumber
        '参    数: strName = 名称
        '          strValue = 字符串值
        '          sngMax = 最大值
        '          sngMin = 最小值
        '返 回 值: True = OK
        '          False = 输入错误
        '功能描述: 检查文本框输入的有效性（数字，最大值，最小值）
        '=====================================================================
        Public Function CheckTextNumber(ByVal strName As String, ByVal strValue As String,
                                        ByVal sngMax As Single, ByVal sngMin As Single) As Boolean

            If strValue = "" Then
                log.WriteLogError("输入参数检查", "[" & strName & "]不能为空！")
                Return False
            ElseIf Not IsNumeric(strValue) Then
                log.WriteLogError("输入参数检查", "[" & strName & "]请填数字！")
                Return False
            ElseIf CSng(strValue) > sngMax Then
                log.WriteLogError("输入参数检查", "[" & strName & "]不能大于[" & sngMax & "]！")
                Return False
            ElseIf CSng(strValue) < sngMin Then
                log.WriteLogError("输入参数检查", "[" & strName & "]不能小于[" & sngMin & "]！")
                Return False
            End If

            Return True
        End Function


        '=====================================================================
        '函 数 名:CheckIP
        '参    数:strIP = IP字符串(192.168.0.1)
        '返 回 值:True=正确，False=错误
        '功能描述:检查IP地址的正确性
        '=====================================================================
        Public Function CheckIP(strName As String, strIP As String) As Boolean
            Dim str1 As String() = Split(strIP.ToLower, ".")  '分解参数

            If str1.Length <> 4 Then
                log.WriteLogError("输入参数检查", "[" & strName & "]IP缺少.分隔！")
                Return False '参数错误(缺少.分隔)
            End If

            Dim i As Byte

            For i = 0 To 3
                If Len(str1(i)) > 3 Then
                    log.WriteLogError("输入参数检查", "[" & strName & "]IP位数过多！")
                    Return False '参数错误(位数过多)
                End If

                If Not IsNumeric(str1(i)) Then
                    log.WriteLogError("输入参数检查", "[" & strName & "]IP非数字！")
                    Return False '参数错误(非数字)
                End If

                If CInt(str1(i)) < 0 Or CInt(str1(i)) > 255 Then
                    log.WriteLogError("输入参数检查", "[" & strName & "]IP参数错误，超出0-255！")
                    Return False '参数错误(超出0-255)
                End If
            Next

            Return True '正确
        End Function


        '=====================================================================
        '函 数 名: CheckPathExist
        '参    数: strPath = 文件名称（含路径）
        '返 回 值: True = 存在
        '          False = 不存在
        '功能描述: 检查目录是否存在，并报错存储日志，并新建目录
        '=====================================================================
        Public Function CheckPathExist(strPath As String) As Boolean
            Dim blnFound As Boolean = Directory.Exists(strPath)

            If Not blnFound Then
                log.WriteLogError("完整性自检()", "目录：[" & strPath & "]不存在！已自动新建。")

                Directory.CreateDirectory(g_strJsonPath) '创建目录
            End If

            Return blnFound
        End Function


        '=====================================================================
        '函 数 名: CheckFileExist
        '参    数: strFile = 文件名称（含路径）
        '返 回 值: True = 存在
        '          False = 不存在
        '功能描述: 检查文件是否存在，并报错存储日志
        '=====================================================================
        Public Function CheckFileExist(strFile As String) As Boolean
            Dim blnFound As Boolean = File.Exists(strFile)

            If Not blnFound Then
                log.WriteLogError("完整性自检()", "文件：[" & strFile & "]不存在！")
            End If

            Return blnFound
        End Function


        '=====================================================================
        '函 数 名: ExcelInit
        '参    数: 
        '返 回 值: True = OK,  False = error
        '功能描述: Excel模板相关的初始化
        '=====================================================================
        Private Function ExcelInit() As Boolean
            g_strExcelPath = g_strStartupPath & "Excel模版"

            '目录检查
            If CheckPathExist(g_strExcelPath) = False Then
                Return False
            End If

            Return True
        End Function


        '=====================================================================
        '函 数 名: LogInit
        '参    数: 
        '返 回 值: True = OK,  False = error
        '功能描述: Log日志相关的初始化
        '=====================================================================
        Private Function LogInit() As Boolean
            log = New BoyiLog

            log.UserName = g_strUserName
            log.DatabaseProvider = g_strDatabaseProvider

            log.LogPath = g_strStartupPath & "Log"  '程序启动运行目录

            log.LOG_SAVE_FILE_EN = True
            log.LOG_SAVE_DATABASE_EN = False

            log.LOG_ERROR_EN = True
            log.LOG_ERROR_MSGBOX_EN = False

            log.LOG_WARN_EN = True
            log.LOG_WARN_MSGBOX_EN = False

            log.LOG_INFO_EN = False
            log.LOG_INFO_MSGBOX_EN = False

            log.LOG_DEBUG_EN = False
            log.LOG_DEBUG_MSGBOX_EN = False

            log.LOG_ASSERT_EN = False
            log.LOG_ASSERT_MSGBOX_EN = False

            Return True
        End Function


        '=====================================================================
        '函 数 名: JsonInit
        '参    数: 
        '返 回 值: True = OK,  False = error
        '功能描述: JSON配置相关的初始化
        '=====================================================================
        Private Function JsonInit() As Boolean
            g_strJsonPath = g_strStartupPath & "JSON"

            '目录检查
            If CheckPathExist(g_strJsonPath) = False Then
                Return False
            End If

            '文件检查
            'CheckFileExist(g_strJsonPath & "\IO模块_uart.json")
            'CheckFileExist(g_strJsonPath & "\LPU_tcp-client.json")
            CheckFileExist(g_strJsonPath & "\modbus.json")

            Return True
        End Function


        '=====================================================================
        '函 数 名: BinInit
        '参    数: 
        '返 回 值: True = OK,  False = error
        '功能描述: Bin插件相关的初始化
        '=====================================================================
        Private Function BinInit() As Boolean
            g_strBinPath = g_strStartupPath & "Bin"

            '目录检查
            If CheckPathExist(g_strBinPath) = False Then
                Return False
            End If

            '文件检查
            'CheckFileExist(g_strBinPath & "\OSKLauncher64.exe")
            'CheckFileExist(g_strBinPath & "\快速关机(Ctrl+Alt+End).exe")
            'CheckFileExist(g_strBinPath & "\FoxitReader.exe")
            CheckFileExist(g_strBinPath & "\权限设置说明.txt")

            Return True
        End Function


        '=====================================================================
        '函 数 名: DatabaseInit
        '参    数: 
        '返 回 值: True = OK,  False = error
        '功能描述: 数据库相关的初始化
        '=====================================================================
        Private Function DatabaseInit() As Boolean
            g_strDatabasePath = g_strStartupPath & "数据库"

            CheckPathExist(g_strDatabasePath) '目录检查

            '文件检查
            CheckFileExist(g_strDatabasePath & "\测试记录.mdb")
            CheckFileExist(g_strDatabasePath & "\出厂设定.mdb")
            CheckFileExist(g_strDatabasePath & "\用户设定.mdb")
            CheckFileExist(g_strDatabasePath & "\模板管理.mdb")

            '打开数据库连接
            If OpenDatabase(g_strDatabaseProvider, g_strDatabasePath, SUPER_USER_NAME, SUPER_PASSWORD) = False Then
                Return False
            End If

            Return True
        End Function


        '=====================================================================
        '函 数 名: SystemInit
        '参    数: 
        '返 回 值: 
        '功能描述: 系统初始化
        '=====================================================================
        Public Sub SystemInit()
            SystemStringInit() '字符串初始化

            '数据源目录，没有设置or目录不存在时默认在程序安装目录
            g_strStartupPath = Interaction.GetSetting("MSP-800", "setting", "strStartupPath",
                                                      AppDomain.CurrentDomain.BaseDirectory)
            If (g_strStartupPath = "") Or (Not Directory.Exists(g_strStartupPath)) Then
                g_strStartupPath = AppDomain.CurrentDomain.BaseDirectory
            End If

            '"Microsoft.Jet.OLEDB.4.0"
            '"Microsoft.ACE.OLEDB.12.0"
            g_strDatabaseProvider = Interaction.GetSetting("MSP-800", "setting", "strDatabaseProvider",
                                                           "Microsoft.Jet.OLEDB.4.0")
            If g_strDatabaseProvider = "" Then
                g_strDatabaseProvider = "Microsoft.Jet.OLEDB.4.0"
            End If

            LogInit()       'Log日志初始化(先执行)
            DatabaseInit()  '数据库初始化

            idWorker = New IdWorker(1)

            '日志开关
            log.LOG_SAVE_FILE_EN = Fact_ReadPublicValue("文件日志", True)
            log.LOG_SAVE_DATABASE_EN = Fact_ReadPublicValue("数据库日志", True)

            log.LOG_ERROR_EN = Fact_ReadPublicValue("错误日志保存", True)
            log.LOG_ERROR_MSGBOX_EN = Fact_ReadPublicValue("错误报警", True)

            log.LOG_WARN_EN = Fact_ReadPublicValue("警告日志保存", True)
            log.LOG_WARN_MSGBOX_EN = Fact_ReadPublicValue("警告报警", True)

            log.LOG_INFO_EN = Fact_ReadPublicValue("正常输出信息保存", True)
            log.LOG_INFO_MSGBOX_EN = Fact_ReadPublicValue("正常输出信息报警", True)

            log.LOG_DEBUG_EN = Fact_ReadPublicValue("调试输出信息保存", True)
            log.LOG_DEBUG_MSGBOX_EN = Fact_ReadPublicValue("调试输出信息报警", True)

            log.LOG_ASSERT_EN = Fact_ReadPublicValue("断言输出信息保存", True)
            log.LOG_ASSERT_MSGBOX_EN = Fact_ReadPublicValue("断言输出信息报警", True)

            ExcelInit()     'Excel模版初始化
            JsonInit()      'JSON配置初始化
            BinInit()       'Bin插件初始化

            Read_PublicSet() '读取[全局设定]

            'mdlLPU.StartServer() 'LPU-800打开server
            'mdlIO.StartServer() 'IO扩展模块打开server
            'mdlMotor.StartServer() '步进电机（3个）打开server
        End Sub


        '=====================================================================
        '函 数 名: fun快速关机
        '参    数: 
        '返 回 值:
        '功能描述: 快速关机
        '=====================================================================
        Public Sub fun快速关机()
            CloseDatabase() '关闭数据库连接
            log.LogPath = ""

            ' mdlLPU.StopServer() 'LPU-800关闭server
            'mdlIO.StopServer() 'IO扩展模块关闭server
            'mdlMotor.StopServer() '步进电机（3个）关闭server

            Try
                'Shell(g_strBinPath & "\快速关机(Ctrl+Alt+End).exe")
            Catch ex As Exception
                log.WriteLogError("快速关机", ex.Message)
            End Try
        End Sub


        '=====================================================================
        '函 数 名: OpenPdf
        '参    数: strPdfFileName = PDF文件名（含路径）
        '返 回 值: 
        '功能描述: 阅读PDF文件
        '=====================================================================
        Public Sub OpenPdf(ByVal strPdfFileName As String)
            If strPdfFileName = "" Then
                log.WriteLogError("OpenPdf()", "没有指定PDF文件！")
                Exit Sub
            ElseIf Not File.Exists(strPdfFileName) Then
                log.WriteLogError("OpenPdf()", "PDF文件[" & strPdfFileName & "]找不到！")
                Exit Sub
            End If

            Dim strExeFileName As String = ""

            If Fact_ReadPublicValue("pdf阅读器方式", 0) = 0 Then '内置
                strExeFileName = g_strBinPath & "\FoxitReader.exe"
            Else '外置
                strExeFileName = Fact_ReadPublicValue("pdf阅读器",
                                                      "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe")
            End If

            If strExeFileName = "" Then
                log.WriteLogError("OpenPdf()", "没有指定PDF阅读软件！")
                Exit Sub
            ElseIf Not File.Exists(strExeFileName) Then
                log.WriteLogError("OpenPdf()", "阅读软件[" & strExeFileName & "]找不到！")
                Exit Sub
            End If

            Try
                'Shell(strExeFileName & " " & strPdfFileName, AppWinStyle.MaximizedFocus)
            Catch ex As Exception
                log.WriteLogError("OpenPdf()", ex.Message)
            End Try
        End Sub


        '=====================================================================
        '函 数 名: OpenKeyboard
        '参    数: 
        '返 回 值: 
        '功能描述: 弹出虚拟键盘
        '=====================================================================
        Public Sub OpenKeyboard()
            Try
                'Shell(g_strBinPath & "\OSKLauncher64.exe")
            Catch ex As Exception
                log.WriteLogError("打开屏幕键盘", "未正常打开屏幕键盘！")
            End Try
        End Sub

        Public Function FillInSpaces(ByVal source As String, ByVal length As Integer) As String
            If source.Length >= length Then
                Return Mid(source, 1, length)
            Else
                Dim sb As StringBuilder = New StringBuilder()
                For i = 0 To length - source.Length - 1
                    sb.Append(" ")
                Next
                sb.Append(source)
                Return sb.ToString()
            End If
        End Function
    End Module
End Namespace